To make your Web site a productive gateway between you and your customers, you need a CGI application -- the right CGI application.
Jon Wiederspan
Creating a Mac-based Web site is amazingly easy. With server software, a direct connection to the Internet, and the HTML pages and graphics that make up your site, you're in business. Basic Web pages aren't very interactive, though: They can provide links only to predefined pages, and they don't allow users to conduct searches or send information to the site's owner. If you want to perform business transactions on the Web or let users search your database, it's time to take the next step: You need a CGI application.
If you've filled out an online form, clicked on a Web-based map, or bought anything from an electronic mall, you've probably encountered a CGI application. CGI stands for Common Gateway Interface. The CGI standard defines an interface through which information server software (such as Web server software) can communicate with other applications on the server or on the network. Software that exchanges data via this interface -- a CGI application -- gives Web servers new features, such as forms processing, image mapping, and linking to databases. You'll find CGI applications running on almost all Web servers, including UNIX and Windows NT platforms and the Macintosh. To help you choose the right applications for your Web site, here's a guide to using CGI applications, the issues you'll face when working with them, and the key points to consider when making your choices.
What's a CGI Application Good For?
CGI applications can bring life to your Web site, by adding features to the server software itself and linking the site to other applications.
Image-map processing is the most common example of a CGI application that adds to server software. It's also one of the simplest. An image map is a Web-page graphic element that contains "hot spots." When you click on a hot spot, a CGI application retrieves an HTML page that matches your request. You might, for example, click on a city on a map of the U.S. to view a page containing information about businesses in that city. Unlike standard HTML pages, image maps allow you to include a lot of hot spots within a single graphic element.
In addition to enhancing server software, CGI applications can link Web servers with database managers, statistical packages, and other applications in order to bring a wide variety of information to the Web. If, for example, you provide a searchable product catalog, a user can enter a keyword into an HTML form. The CGI application sends the request to a database program and tells it to return the results of the search as an HTML page. This CGI function is called HTML on the fly, because the application generates a new page each time the database is searched. Webmasters can also use CGI applications to count Web-page "hits" and send the data to a spreadsheet program for analysis and reporting.
Preparing for Problems
Although CGI applications add greatly to a Web site, they're not without problems. You need to prepare for the impact on speed, security, and system stability when you add CGI applications to your Web server.
Slower response.
When you use CGI applications with a Web server, you reduce the potential server speed. A single CGI application -- particularly if it's a simple one, such as an image-map processor -- may not place much strain on the server, but speed can decrease as you add more CGI applications. Servers slow down because CGI applications compete with the Web server software for resources, including CPU time, disk access, and network bandwidth. The degree of resource competition varies widely among CGI applications. Using a CGI application to publish an image map requires little server horsepower, but providing access to databases consumes disk-access and CPU time. You can minimize database-related slowdowns by storing database applications and files on a separate server, leaving the Web server to handle Web connections and CGI applications.
Security risks.
While you're counting CGI applications, consider this: Every CGI application you add to the server is a potential security risk. That's because CGI applications can do things your server wouldn't normally allow users to do. Most server software has built-in security measures to protect files and folders. A well-designed server will provide a way for CGI applications to comply with these security measures before it returns a file to a user, but it is very easy for a CGI application to simply ignore these security measures and access whatever file it wants.
A less stable system.
Like Web server software, CGI applications must be stable enough to deal with the demands of processing Web-access requests. Even commercial CGI applications can be unstable at times, and when they crash, they can take your whole server with them. When you install a new CGI application, test the system exhaustively before making the site available to the public.
What to Look For
Several commercial and shareware Mac CGI applications are available -- mostly distributed through the Web. If you're a programmer, you can write your own, although it's a good idea to check out the professionally developed options first (see the "Finding CGI Applications" sidebar). Selecting the proper CGI application to use on your server can be hard. In general, you should look for the following characteristics in CGI applications you buy:
Fast, compiled language.
CGI applications written in C or another compiled programming language are usually preferable to those written in a scripting language, such as AppleScript or UserLand's Frontier. Compiled CGI applications are faster and generally have more features and a better interface. Because they consist of a single file, they also tend to consume less memory, are easy to install, and are not subject to damage inflicted by a Webmaster's tinkering with the code. Many amateur and professional developers use AppleScript to create CGI applications, but these, unlike CGI applications written in a compiled language, are generally slower and more difficult to maintain; because they consist of multiple files that must be installed and configured in certain ways, one file out of place can cause the whole CGI-application framework to come undone. Frontier-based CGI applications offer some advantages over those written in AppleScript -- they are often faster, for example.
Responsive tech support.
Support should be a major consideration when you're choosing CGI applications for commercial Web sites. Look for developers that provide mailing lists where users can discuss problems and suggest new features. The company may also make these lists searchable online or supply a FAQ (Frequently Asked Questions) list for new users. Because broken CGI applications can bring your Web site to a screeching halt, you should additionally look for developers that provide prompt response to problems, via phone and e-mail. A company that doesn't provide online support for its CGI application is a company to be avoided.
A track record.
Given the Web's relative youth, it may seem strange to fault a CGI-application developer whose product is new to the market. There's a big difference, though, between a product that's been around for a year or more and one that was only recently introduced. Very few companies get it right the first time around -- especially on the Internet, where technologies can change drastically in the time it takes to release a shipping product. If you find yourself choosing between an older product with an established user base and a newer product with more-exciting advertising, take the old-timer. Here's a tip: A company's mailing-list archives can also give you an idea of a product's reputation among its users. If you notice chronic user complaints or an unresponsive developer, look elsewhere.
CGI applications give you the tools to operate a useful and interactive Web site, but software is not a shortcut for an organized, well-designed set of pages. To get the most from CGI applications, plan the rest of your site as carefully as you seek out good software.
Jon Wiederspan is director of technical services for ComVista, an Internet consulting group in Redmond, Washington, and is coauthor of Planning and Managing Web Sites on the Macintosh (Addison-Wesley).
Finding CGI Applications
Shelly Brisbin
Several organizations offer CGI tutorials and maintain lists of Mac CGI applications. Here are some of the best resource collections:
ComVista (http://www.comvista.com/net): Tutorials on writing CGI applications, plus links to a wide variety of Mac Internet tools.
Mac OS WWW Page (http://www.ape.com/webstar): An unabashed evangelism site for Mac Web servers and tools, including CGI applications.
Macintosh WWW FAQ (http://arpp1.carleton.ca/mac/): Comprehensive list of Web client, server, and CGI tools.
WebEdge Resources (http://www.webedge.com/resources): Resource collection from sponsors of a semiannual Mac Web development conference.
Web66 (http://web66.coled.umn.edu): Web development resources and tutorials geared toward educators.
How CGI Apps Work
Database access is one of the most important purposes of CGI applications on the Web. You can, for example, give customers access to a product catalog and track their information requests. If you're very ambitious, you can make sales right from your Web site.
1. User enters keywords into an HTML form and clicks on Submit.
2. The Web browser sends the user's request to the Web server software.
3. The server software forwards the keywords to a CGI application designed to convert requests into database-search queries.
4. The CGI application sends the search query to the database application.
5. The database application performs the search and sends the results to the CGI application.
6. The CGI application converts the results into HTML text and sends it to the server.
7. The server software sends the reply to the Web browser.